package com.yy.wmmaccmsapp.utils


import android.content.Context
import android.text.TextUtils
import com.google.gson.Gson
import com.tencent.mmkv.MMKV
import com.yy.wmmaccmsapp.bean.KamiBean


object CacheUtil {

    fun initMMKV(context: Context){
        MMKV.initialize(context)
    }

    fun getKv(): MMKV {
        val kv = MMKV.mmkvWithID("appthis")
        return kv
    }

    fun setKamiInfo(value: String) {
        getKv().encode("kamiinfo", value)
    }

    fun removeKey(key: String) {
        getKv().reKey(key)
    }

    fun getKamiInfo(): KamiBean? {
        var value = getKv().decodeString("kamiinfo")
        if(TextUtils.isEmpty(value)){
            return null
        }
        var camibean = Gson().fromJson(value,KamiBean::class.java)
        return camibean
    }

    fun setFristTime(time: Long) {
        getKv().encode("fristtime", time)
    }

    fun getFristTime(): Long {

        return getKv().decodeLong("fristtime",-1)
    }

}